package com.zx.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zx.sys.domain.Menu;
import com.zx.sys.mapper.MenuMapper;
import com.zx.sys.service.MenuService;
import com.zx.sys.utils.DataGridView;
import com.zx.sys.vo.MenuVo;

@Service
public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenuMapper menuMapper;
	
	@Override
	public List<Menu> queryAllMenuForList(MenuVo menuVo) {

		return menuMapper.queryAllMenu(menuVo);
	}

	@Override
	public List<Menu> queryMenuByUserIdForList(MenuVo menuVo,Integer userId) {

		return menuMapper.queryMenuByUserId(menuVo.getAvailable(),userId);
	}

	@Override
	public DataGridView queryAllMenu(MenuVo menuVo) {
		Page<Object> page = PageHelper.startPage(menuVo.getPage(), menuVo.getLimit());
		List<Menu> data = menuMapper.queryAllMenu(menuVo); 
		return new DataGridView(page.getTotal(), data);
	}

	@Override
	public void addMenu(MenuVo menuVo) {
		menuMapper.insertSelective(menuVo);
	}

	@Override
	public void updateMenu(MenuVo menuVo) {
		menuMapper.updateByPrimaryKeySelective(menuVo);
	}

	@Override
	public Integer queryMenuByPid(Integer id) {
		return menuMapper.queryMenuByPid(id);
	}

	@Override
	public void deleteMenu(MenuVo menuVo) {
		menuMapper.deleteByPrimaryKey(menuVo.getId());
		
		menuMapper.deleteRoleMenuByMid(menuVo.getId());
	}
}
